﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Coleotrack.Data;
using Coleotrack.Service.Contracts;
using log4net;

namespace Coleotrack.Controllers
{
    [IfInstalled]
    public class IssueController : Controller
    {
        private readonly ILog logger;

        public IIssueService IssueService { get; private set; }

        public IssueController(IIssueService issueService)
        {
            IssueService = issueService;
            logger = LogManager.GetLogger(typeof (IssueController));
        }

        [HttpGet, Authorize]
        public ActionResult List()
        {
            var issues = IssueService.All().ToList();
            return View(issues);
        }

        [HttpGet, Authorize]
        public ActionResult Details(int id)
        {
            try
            {
                var issue = IssueService.Find(id);
                return View(issue);
            }
            catch(Exception ex)
            {
                logger.Warn(string.Format("Failed to get issue with id {0}", id), ex );
                return View("NotFound");
            }
        }
    }
}
